<template>
	<view class="commission-details" ref="container">
		<view class="promoterHeader bg-color-red">
			<view class="headerCon acea-row row-between-wrapper">
				<view>
					<view class="name">待收益</view>
					<view class="money">
						￥
						<text class="num">{{ brokeragePrice }}</text>
					</view>
				</view>
				<view class="iconfont icon-jinbi1"></view>
			</view>
		</view>
		<view class="sign-record" ref="content">
			<view class="list">
				<view class="item" v-for="(item, infoIndex) in info" :key="infoIndex">
					<view class="data">{{ item.time }}</view>
					<view class="listn" v-for="(val, indexn) in item.list" :key="indexn">
						<view class="itemn acea-row row-between-wrapper">
							<view>
								<view class="name line1">{{typeMap[val.type]}} | {{ val.title }}</view>
								<view>{{ val.addTime }}</view>
							</view>
							<view class="num" v-if="val.pm == 1">+{{ val.number }}</view>
							<view class="num font-color-red" v-if="val.pm == 0">-{{ val.number }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<Loading :loaded="loaded" :loading="loading"></Loading>
	</view>
</template>
<script>
	// import { getCommissionInfo, getSpreadInfo } from "@/api/user";
	import {
		commissionApp
	} from "@/api/user";
	import Loading from "@/components/Loading";

	export default {
		name: "CashRecord",
		components: {
			Loading
		},
		props: {},
		data: function() {
			return {
				info: [],
				commission: 0,
				where: {
					page: 1,
					limit: 10,
					
					// 扩展
					type1: 0
				},
				types: 4,
				loaded: false,
				loading: false,
				
				typeMap: {
					'pay_product': '消费',
					'recharge': '充值',
					'brokerage': '返佣',
					'extract': '提现',
					'sign': '签到积分',
					'pay_product_refund': '退款',
					'system_add': '系统增加',
					'system_sub': '系统减少',
					'deduction': '减去',
					'gain': '奖励',
					'price_difference': '差价',
					'convert': '释放金额',
					'distribution':'分销返佣'
				},
				brokeragePrice: 0
			};
		},
		mounted: function() {
			// this.getCommission();
			// this.getIndex();
			console.log(this.$yroute.query.brokeragePrice)
			this.brokeragePrice = this.$yroute.query.brokeragePrice
			this.loadData()
		},
		onReachBottom() {
			this.loading === false && this.loadData();
		},
		methods: {
			loadData() {
				let that = this;
				if (that.loading == true || that.loaded == true) return;
				that.loading = true;
				commissionApp(that.where, 0).then(
					res => {
						that.loading = false;
						if (res.data) {
							that.loaded = res.data[0].list.length < that.where.limit;
							that.where.page = that.where.page + 1;
							that.info.push.apply(that.info, res.data);
							console.log(that.loaded)
						} else {
							that.loaded = false
						}
						
					},
					err => {
						uni.showToast({
							title: err.msg || err.response.data.msg || err.response.data.message,
							icon: 'none',
							duration: 2000
						});
					}
				);
			},
			getIndex: function() {
				let that = this;
				if (that.loading == true || that.loaded == true) return;
				that.loading = true;
				getCommissionInfo(that.where, that.types).then(
					res => {
						that.loading = false;
						that.loaded = res.data.length < that.where.limit;
						that.where.page = that.where.page + 1;
						that.info.push.apply(that.info, res.data);
					},
					err => {
						uni.showToast({
							title: err.msg || err.response.data.msg || err.response.data.message,
							icon: 'none',
							duration: 2000
						});
					}
				);
			},
			getCommission: function() {
				let that = this;
				getSpreadInfo().then(
					res => {
						that.commission = res.data.commissionCount;
					},
					err => {
						uni.showToast({
							title: err.msg || err.response.data.msg || err.response.data.message,
							icon: "none",
							duration: 2000
						});
					}
				);
			}
		}
	};
</script>